package cloud.seri.auth.service.mapper

import cloud.seri.auth.domain.User
import cloud.seri.auth.service.dto.UserDTO
import org.mapstruct.Mapper
import org.mapstruct.Mapping
import org.mapstruct.Mappings

/**
 * Mapper for the entity [User] and its DTO called [UserDTO].
 *
 * Normal mappers are generated using MapStruct, this one is hand-coded as MapStruct
 * support is still in beta, and requires a manual step with an IDE.
 */
@Mapper(componentModel = "spring", uses = [DeptMapper::class])
interface UserMapper : EntityMapper<UserDTO, User>
{
    @Mappings(Mapping(source = "dept.id", target = "deptId"), Mapping(target = "roles", ignore = true))
    override fun toDto(entity: User): UserDTO

    @Mappings(Mapping(source = "deptId", target = "dept"), Mapping(ignore = true, target = "roles"))

    override fun toEntity(dto: UserDTO): User
}
